﻿using System;
using System.Linq;
using RanchBuddy.Core.Domain.Impl;
using StructureMap;

namespace RanchBuddy.Core.DataAccess.Impl
{
    [Pluggable("Default")]
    public class HelpMessageRepository : IHelpMessageRepository
    {
        public static string GetHelpMessageBodyByID(Int32 HelpMessageID)
        {
            string result = "";

            using (RanchBuddyDataContext dc = ObjectFactory.GetInstance<IConnection>().GetLsContext())
            {
                result =
                    dc.HelpMessages
                        .Where(m => m.HelpMessageID == HelpMessageID)
                        .Select(m => m.Body)
                        .FirstOrDefault() ?? "";
            }
            return result;
        }

        public static HelpMessage GetHelpMessageByID(Int32 HelpMessageID)
        {
            HelpMessage result = null;

            using (RanchBuddyDataContext dc = ObjectFactory.GetInstance<IConnection>().GetLsContext())
            {
                result =
                    dc.HelpMessages
                        .Where(m => m.HelpMessageID == HelpMessageID)
                        .FirstOrDefault();
            }

            return result;
        }
    }
}
